<?php
	require '../conn.php';
	$shopId = trim($_REQUEST['shopid']);
	$content = trim($_REQUEST['content']);
	$uid = trim($_REQUEST['uid']);
	
	$currentTime = time();
	
	if ($shopId =="" || $content=="" || $uid=="")
	{
		echo "{\"error\":1,\"message\":\"评论信息不完整\"}";
		exit;
	}
	
	$checkQuery = "SELECT * FROM comments WHERE uid=".$uid." and shop_id=".$shopId;
	$checkResult = mysql_query($checkQuery);
	
	if ($myrow = mysql_fetch_row($checkResult)) {
		echo "{\"error\":1,\"message\":\"您已经评论过该店铺\"}";
		exit;
	}
	
	$query = "INSERT INTO comments(shop_id, content, uid, createtime)"
						."VALUES('$shopId','$content','$uid','$currentTime')";
						
	$result = mysql_query($query);
	$rowid = mysql_insert_id();
	if ($rowid > 0) {
		echo "{\"success\":0,\"message\":\"评论成功\"}";
	}
	else {
		echo "{\"error\":1,\"message\":\"评论失败\"}";
	}
			
?>